// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import store from './vuex/store'
import axios from './axios'
import api from './api'
import i18n from './i18n'
import { sync } from 'vuex-router-sync'
import jquery from 'jquery'
import VueCookies from 'vue-cookies'
import 'element-ui/lib/theme-chalk/index.css'

Vue.prototype.$axios = axios
Vue.prototype.$jquery = jquery
Vue.prototype.$api = api

Vue.use(ElementUI)
Vue.use(VueCookies)
sync(store, router)

Vue.config.productionTip = false

router.beforeEach(function (to, from, next) {
  if (store.state.loginData.login) {
    store.commit('updateLoadingStatus', true)
    next()
  } else {
    if (to.path.indexOf('/main') === -1) {
      store.commit('updateLoadingStatus', true)
      next()
    } else {
      next('/')
    }
  }
})

router.afterEach(function (to) {
  setTimeout(() => {
    store.commit('updateLoadingStatus', false)
  }, 400)
})

/* eslint-disable no-new */
new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
